<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8"/>
    <title>Es-仿京东搜索-爬虫</title>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
    <script th:src="@{/js/jquery.min.js}"></script>
</head>

<body class="pg">
<div class="page" id="app">
    <div id="mallPage" class=" mallist tmall- page-not-market ">

        <!-- 头部搜索 -->
        <div id="header" class=" header-list-app" style="height: 200px">
            <div class="headerLayout">
                <div class="headerCon ">
                    <!-- Logo-->
                    <h1 id="mallLogo">
                        <img th:src="@{/images/jdlogo.png}" alt="">
                    </h1>

                    <div class="header-extra">
                        <!--爬取-->
                        <div id="mallSearch" class="mall-search">
                            <form name="parseTop" class="mallSearch-form clearfix">
                                <div class="mallSearch-input clearfix">
                                    <div class="s-combobox" id="s-combobox-685">
                                        <div class="s-combobox-input-wrap">
                                            <input v-model="key" type="text" autocomplete="off" value="dd"
                                                   id="mq"
                                                   class="s-combobox-input" aria-haspopup="true">
                                            <button type="submit" @click.prevent="parseKey" id="searchbtn">爬取
                                            </button>
                                        </div>

                                    </div>
                                </div>
                            </form>
                        </div>
                        <!--搜索-->
                        <div id="mallSearch" class="mall-search">
                            <form name="searchTop" class="mallSearch-form clearfix">
                                <fieldset>
                                    <legend>天猫搜索</legend>
                                    <div class="mallSearch-input clearfix">
                                        <div class="s-combobox" id="s-combobox-685">
                                            <div class="s-combobox-input-wrap">
                                                <input v-model="keyword" type="text" autocomplete="off" value="dd"
                                                       id="mq"
                                                       class="s-combobox-input" aria-haspopup="true">
                                            </div>
                                        </div>
                                        <button type="submit" @click.prevent="searchKey" id="searchbtn">搜索</button>
                                    </div>
                                </fieldset>
                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div>

        <!-- 商品详情页面 -->
        <div id="content">
            <div class="main">
                <!-- 品牌分类 -->
                <form class="navAttrsForm">
                    <div class="attrs j_NavAttrs" style="display:block">
                        <div class="brandAttr j_nav_brand">
                        </div>
                    </div>
                </form>

                <!-- 排序规则 -->

                <!-- 商品详情 -->
                <div class="view grid-nosku">

                    <div class="product" v-for="result in result">
                        <div class="product-iWrap">
                            <!--商品封面-->
                            <div class="productImg-wrap">
                                <a class="productImg">
                                    <img :src="result.img">
                                </a>
                            </div>
                            <!--价格-->
                            <p class="productPrice">
                                <em>{{result.price}}</em>
                            </p>
                            <!--标题-->
                            <p class="productTitle">
                                <a v-html="result.title"></a>
                            </p>
                            <!-- 店铺名 -->
                            <div class="productShop">
                                <span>{{result.shopName}}</span>
                            </div>
                            <!-- 成交信息 -->
                            <!--  <p class="productStatus">
                                  <span>月成交<em>999笔</em></span>
                                  <span>评价 <a>3</a></span>
                              </p>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/js/axios.min.js}"></script>
<script th:src="@{/js/vue.min.js}"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            keyword: '',  //搜索的关键字
            result: [], //搜索的结果
            kresults: [],
            key: ''
        },
        methods: {
            searchKey() {
                var keyword = this.keyword
                axios.get('search/' + keyword + '/1/210').then(response => {
                    console.log(response);
                    this.result = response.data;//绑定数据！
                })
            },
            parseKey() {
                var key = this.key
                axios.get('parse/' + key).then(
                    response => {
                        if (response != null) {
                            console.log("爬取成功")
                            console.log(response);
                            this.kresults = response.data;
                        } else {
                            console.log("爬取失败")
                        }
                    }
                )
            }
        }
    })

</script>

</body>
</html>